<?php
require_once '../include/common.inc.php';
require_once '../include/cart.class.php';
if (!checkAdmin()) {
   header("LOCATION:index.php");
  exit;
}
$menu_index = 2;
$page_title = 'TABLA';
$guide_message = 'Customer | Order Information | Send Invoice No.(Eng)';

getMyParam('cid');
$sql="select * from cus_order where id=$cid";
$query = $db->query($sql);
$order_ary = $db->fetch_array($query);
$order_date=date("Y-m-d",$order_ary["date"]);
$deliveraddress = $order_ary['d_street'] . "<br>" . $order_ary['d_city'] . "<br>" . $order_ary['d_state'] . "<br>" . $order_ary['d_zip'] . "<br>" . $order_ary['d_country'];
$invoiceno=date("Y")."-Web-".$cid;
$order_ary['card_number']=substr($order_ary['card_number'],-4);
/////////////////////////////////////////////////////////get cart information/////////////
$cart_info=new cart;

$cart_info=unserialize($order_ary['cart_info']);
$cart_info_ary = $cart_info->getData();

foreach ($cart_info_ary as $k=>$v) 
{
	if ($v['type'] == 'Courses / Programs') {
		$commission += $v['cost']*$c_r_trainings/100;
	} elseif ($v['productinfo']['is_special'] == 1) {
		$commission += $v['cost']*$c_r_special/100;
	} else {
		$commission += $v['cost']*$c_r_products/100;
	}

	if (isset($v['special_flag']) && $v['special_flag']>0 ) {
		$price_show = "<span style='TEXT-DECORATION: line-through'>" . $v['old_price'] . "</span><br>" . $v['price'];
	} else {
		$price_show = $v['price'];
	}

	$cart_list .= '<tr>
			<td class="en_black_12">'. $v['name'] .'</td>
			<td class="en_black_12">'. $price_show .'</td>
			<td class="en_black_12">'. $v['count'] .'</td>
			<td class="en_black_12">'. $v['cost'] .'</td>
		  </tr>';
}

$totalCost=$cart_info->getTotalCost();
$discount=$cart_info->getDisCount();
$new_total=number_format($totalCost-$discount,2,'.','');
$vat_fee=$cart_info->getAddVat();
$addshippingfee=$cart_info->getAddShippingFee();
$totalCost2=$cart_info->getTotalCost2();

$cart_list .= '<tr>
			<td class="en_black_12" colspan="4" align="right">
				<strong>Sub Total:</strong> DKK'.$totalCost.'<br/> 
				<strong>Discount:</strong> DKK'.$discount.'<br/>
				<strong>New Sub Total:</strong> DKK'.$new_total.'<br/> 
				<strong>VAT:</strong> DKK'.$vat_fee.'<br/> 
				<strong>Shipping Fee:</strong> DKK'.$addshippingfee.'<br/> 
				<strong>Total:</strong> '.$totalCost2.'</td>				
		  </tr>';
////////////////////////////////////////////////
//Customer Details
$sql="select * from cus_members where id=".$order_ary['user_id'];
$query = $db->query($sql);
$customer_ary = $db->fetch_array($query);
$username = empty($customer_ary['lastname']) ? $customer_ary['firstname'] : $customer_ary['firstname'] . ' ' . $customer_ary['lastname'];
$user_address = $customer_ary['street'] . "<br>" . $customer_ary['city'] . "<br>" . $customer_ary['state'] . "<br>" . $customer_ary['zip'] . "<br>" . $customer_ary['country'];
$email = $customer_ary['email'];
//Promoter Details
$sql="select * from promoter_info where id=".$order_ary['promoter_id'];
$query = $db->query($sql);
$promoter_ary = $db->fetch_array($query);
$promoter_name = empty($promoter_ary['lastname']) ? $promoter_ary['firstname'] : $promoter_ary['firstname'] . ' ' . $promoter_ary['lastname'];
$promoter_id=$promoter_ary['id'];
//Other Info
$order_ary['card_type']=$CARD_TYPE_ARY[$order_ary['card_type']];

if(!isset($_POST["send"]))
	$btn_send="<input name=\"print\" type=\"button\" id=\"btnPrint\" value=\" Print \"  class=\"button\" onclick=\"openwin('c_order_invoice_print.php?cid=".$cid."',500,600,100,150);\"/>&nbsp;&nbsp;&nbsp;&nbsp;<input name=\"send\" type=\"submit\" id=\"send\" value=\" Send \"  class=\"button\"/>&nbsp;&nbsp;&nbsp;&nbsp;<input name=\"cancel\" type=\"button\" id=\"cancel\" value=\"Cancel\"  class=\"button\" onClick=\"javascript:history.back(-1);\"/>&nbsp;&nbsp;&nbsp;&nbsp;";
$today=date("M d,Y");
include '../mail/invoice_to_members.php';
if($_POST["send"]!="")
 {
		$subject = "Invoice ".$invoiceno." - Acuity World Webshop (English)";
		//send mail to member
 		sendhtmlmail($from_name,$from_email,$to_name,$to_email,$subject,$content);
		//send a copy mail to admin
		$subject = "Copy of Invoice ".$invoiceno." - Acuity World Webshop (English)";
		$to_name = $webmaster_name;
		$to_email = $webmaster_email;
		sendhtmlmail($from_name,$from_email,$to_name,$to_email,$subject,$content);
		
		$sql_invoice="update cus_order set invoiceno='$invoiceno' where id=$cid";
		$db->query($sql_invoice);
 		$msg="This Order Invoice has been send. ";
		$href="c_order.php";
		include_once('menu_list.php');
		require_once PrintEot('a_header');
		require_once PrintEot('a_msg');
		require_once PrintEot('a_footer');
		exit;
 }   

include_once('menu_list.php');
require_once PrintEot('a_header');
echo $content;
require_once PrintEot('a_footer');
?>
